home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Objects / listobject.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-28  |  15.1 KB  |  809 lines  |  [TEXT/CWIE]

  1. /***********************************************************
  2. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  3. The Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI or Corporation for National Research Initiatives or
  13. CNRI not be used in advertising or publicity pertaining to
  14. distribution of the software without specific, written prior
  15. permission.
  16.  
  17. While CWI is the initial source for this software, a modified version
  18. is made available by the Corporation for National Research Initiatives
  19. (CNRI) at the Internet address ftp://ftp.python.org.
  20.  
  21. STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
  22. REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  23. MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
  24. CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  25. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  26. PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  27. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  28. PERFORMANCE OF THIS SOFTWARE.
  29.  
  30. ******************************************************************/
  31.  
  32. /* List object implementation */
  33.  
  34. #include "allobjects.h"
  35. #include "modsupport.h"
  36. #include "ceval.h"
  37. #ifdef STDC_HEADERS
  38. #include <stddef.h>
  39. #else
  40. #include <sys/types.h>        /* For size_t */
  41. #endif
  42.  
  43. #define ROUNDUP(n, block) ((((n)+(block)-1)/(block))*(block))
  44.  
  45. static int
  46. roundup(n)
  47.     int n;
  48. {
  49.     if (n < 500)
  50.         return ROUNDUP(n, 10);
  51.     else
  52.         return ROUNDUP(n, 100);
  53. }
  54.  
  55. #define NRESIZE(var, type, nitems) RESIZE(var, type, roundup(nitems))
  56.  
  57. object *
  58. newlistobject(size)
  59.     int size;
  60. {
  61.     int i;
  62.     listobject *op;
  63.     size_t nbytes;
  64.     if (size < 0) {
  65.         err_badcall();
  66.         return NULL;
  67.     }
  68.     nbytes = size * sizeof(object *);
  69.     /* Check for overflow */
  70.     if (nbytes / sizeof(object *) != size) {
  71.         return err_nomem();
  72.     }
  73.     op = (listobject *) malloc(sizeof(listobject));
  74.     if (op == NULL) {
  75.         return err_nomem();
  76.     }
  77.     if (size <= 0) {
  78.         op->ob_item = NULL;
  79.     }
  80.     else {
  81.         op->ob_item = (object **) malloc(nbytes);
  82.         if (op->ob_item == NULL) {
  83.             free((ANY *)op);
  84.             return err_nomem();
  85.         }
  86.     }
  87.     op->ob_type = &Listtype;
  88.     op->ob_size = size;
  89.     for (i = 0; i < size; i++)
  90.         op->ob_item[i] = NULL;
  91.     NEWREF(op);
  92.     return (object *) op;
  93. }
  94.  
  95. int
  96. getlistsize(op)
  97.     object *op;
  98. {
  99.     if (!is_listobject(op)) {
  100.         err_badcall();
  101.         return -1;
  102.     }
  103.     else
  104.         return ((listobject *)op) -> ob_size;
  105. }
  106.  
  107. static object *indexerr;
  108.  
  109. object *
  110. getlistitem(op, i)
  111.     object *op;
  112.     int i;
  113. {
  114.     if (!is_listobject(op)) {
  115.         err_badcall();
  116.         return NULL;
  117.     }
  118.     if (i < 0 || i >= ((listobject *)op) -> ob_size) {
  119.         if (indexerr == NULL)
  120.             indexerr = newstringobject("list index out of range");
  121.         err_setval(IndexError, indexerr);
  122.         return NULL;
  123.     }
  124.     return ((listobject *)op) -> ob_item[i];
  125. }
  126.  
  127. int
  128. setlistitem(op, i, newitem)
  129.     register object *op;
  130.     register int i;
  131.     register object *newitem;
  132. {
  133.     register object *olditem;
  134.     register object **p;
  135.     if (!is_listobject(op)) {
  136.         XDECREF(newitem);
  137.         err_badcall();
  138.         return -1;
  139.     }
  140.     if (i < 0 || i >= ((listobject *)op) -> ob_size) {
  141.         XDECREF(newitem);
  142.         err_setstr(IndexError, "list assignment index out of range");
  143.         return -1;
  144.     }
  145.     p = ((listobject *)op) -> ob_item + i;
  146.     olditem = *p;
  147.     *p = newitem;
  148.     XDECREF(olditem);
  149.     return 0;
  150. }
  151.  
  152. static int
  153. ins1(self, where, v)
  154.     listobject *self;
  155.     int where;
  156.     object *v;
  157. {
  158.     int i;
  159.     object **items;
  160.     if (v == NULL) {
  161.         err_badcall();
  162.         return -1;
  163.     }
  164.     items = self->ob_item;
  165.     NRESIZE(items, object *, self->ob_size+1);
  166.     if (items == NULL) {
  167.         err_nomem();
  168.         return -1;
  169.     }
  170.     if (where < 0)
  171.         where = 0;
  172.     if (where > self->ob_size)
  173.         where = self->ob_size;
  174.     for (i = self->ob_size; --i >= where; )
  175.         items[i+1] = items[i];
  176.     INCREF(v);
  177.     items[where] = v;
  178.     self->ob_item = items;
  179.     self->ob_size++;
  180.     return 0;
  181. }
  182.  
  183. int
  184. inslistitem(op, where, newitem)
  185.     object *op;
  186.     int where;
  187.     object *newitem;
  188. {
  189.     if (!is_listobject(op)) {
  190.         err_badcall();
  191.         return -1;
  192.     }
  193.     return ins1((listobject *)op, where, newitem);
  194. }
  195.  
  196. int
  197. addlistitem(op, newitem)
  198.     object *op;
  199.     object *newitem;
  200. {
  201.     if (!is_listobject(op)) {
  202.         err_badcall();
  203.         return -1;
  204.     }
  205.     return ins1((listobject *)op,
  206.         (int) ((listobject *)op)->ob_size, newitem);
  207. }
  208.  
  209. /* Methods */
  210.  
  211. static void
  212. list_dealloc(op)
  213.     listobject *op;
  214. {
  215.     int i;
  216.     if (op->ob_item != NULL) {
  217.         for (i = 0; i < op->ob_size; i++) {
  218.             XDECREF(op->ob_item[i]);
  219.         }
  220.         free((ANY *)op->ob_item);
  221.     }
  222.     free((ANY *)op);
  223. }
  224.  
  225. static int
  226. list_print(op, fp, flags)
  227.     listobject *op;
  228.     FILE *fp;
  229.     int flags;
  230. {
  231.     int i;
  232.     fprintf(fp, "[");
  233.     for (i = 0; i < op->ob_size; i++) {
  234.         if (i > 0)
  235.             fprintf(fp, ", ");
  236.         if (printobject(op->ob_item[i], fp, 0) != 0)
  237.             return -1;
  238.     }
  239.     fprintf(fp, "]");
  240.     return 0;
  241. }
  242.  
  243. static object *
  244. list_repr(v)
  245.     listobject *v;
  246. {
  247.     object *s, *comma;
  248.     int i;
  249.     s = newstringobject("[");
  250.     comma = newstringobject(", ");
  251.     for (i = 0; i < v->ob_size && s != NULL; i++) {
  252.         if (i > 0)
  253.             joinstring(&s, comma);
  254.         joinstring_decref(&s, reprobject(v->ob_item[i]));
  255.     }
  256.     XDECREF(comma);
  257.     joinstring_decref(&s, newstringobject("]"));
  258.     return s;
  259. }
  260.  
  261. static int
  262. list_compare(v, w)
  263.     listobject *v, *w;
  264. {
  265.     int len = (v->ob_size < w->ob_size) ? v->ob_size : w->ob_size;
  266.     int i;
  267.     for (i = 0; i < len; i++) {
  268.         int cmp = cmpobject(v->ob_item[i], w->ob_item[i]);
  269.         if (cmp != 0)
  270.             return cmp;
  271.     }
  272.     return v->ob_size - w->ob_size;
  273. }
  274.  
  275. static int
  276. list_length(a)
  277.     listobject *a;
  278. {
  279.     return a->ob_size;
  280. }
  281.  
  282. static object *
  283. list_item(a, i)
  284.     listobject *a;
  285.     int i;
  286. {
  287.     if (i < 0 || i >= a->ob_size) {
  288.         if (indexerr == NULL)
  289.             indexerr = newstringobject("list index out of range");
  290.         err_setval(IndexError, indexerr);
  291.         return NULL;
  292.     }
  293.     INCREF(a->ob_item[i]);
  294.     return a->ob_item[i];
  295. }
  296.  
  297. static object *
  298. list_slice(a, ilow, ihigh)
  299.     listobject *a;
  300.     int ilow, ihigh;
  301. {
  302.     listobject *np;
  303.     int i;
  304.     if (ilow < 0)
  305.         ilow = 0;
  306.     else if (ilow > a->ob_size)
  307.         ilow = a->ob_size;
  308.     if (ihigh < 0)
  309.         ihigh = 0;
  310.     if (ihigh < ilow)
  311.         ihigh = ilow;
  312.     else if (ihigh > a->ob_size)
  313.         ihigh = a->ob_size;
  314.     np = (listobject *) newlistobject(ihigh - ilow);
  315.     if (np == NULL)
  316.         return NULL;
  317.     for (i = ilow; i < ihigh; i++) {
  318.         object *v = a->ob_item[i];
  319.         INCREF(v);
  320.         np->ob_item[i - ilow] = v;
  321.     }
  322.     return (object *)np;
  323. }
  324.  
  325. object *
  326. getlistslice(a, ilow, ihigh)
  327.     object *a;
  328.     int ilow, ihigh;
  329. {
  330.     if (!is_listobject(a)) {
  331.         err_badcall();
  332.         return NULL;
  333.     }
  334.     return list_slice((listobject *)a, ilow, ihigh);
  335. }
  336.  
  337. static object *
  338. list_concat(a, bb)
  339.     listobject *a;
  340.     object *bb;
  341. {
  342.     int size;
  343.     int i;
  344.     listobject *np;
  345.     if (!is_listobject(bb)) {
  346.         err_badarg();
  347.         return NULL;
  348.     }
  349. #define b ((listobject *)bb)
  350.     size = a->ob_size + b->ob_size;
  351.     np = (listobject *) newlistobject(size);
  352.     if (np == NULL) {
  353.         return NULL;
  354.     }
  355.     for (i = 0; i < a->ob_size; i++) {
  356.         object *v = a->ob_item[i];
  357.         INCREF(v);
  358.         np->ob_item[i] = v;
  359.     }
  360.     for (i = 0; i < b->ob_size; i++) {
  361.         object *v = b->ob_item[i];
  362.         INCREF(v);
  363.         np->ob_item[i + a->ob_size] = v;
  364.     }
  365.     return (object *)np;
  366. #undef b
  367. }
  368.  
  369. static object *
  370. list_repeat(a, n)
  371.     listobject *a;
  372.     int n;
  373. {
  374.     int i, j;
  375.     int size;
  376.     listobject *np;
  377.     object **p;
  378.     if (n < 0)
  379.         n = 0;
  380.     size = a->ob_size * n;
  381.     np = (listobject *) newlistobject(size);
  382.     if (np == NULL)
  383.         return NULL;
  384.     p = np->ob_item;
  385.     for (i = 0; i < n; i++) {
  386.         for (j = 0; j < a->ob_size; j++) {
  387.             *p = a->ob_item[j];
  388.             INCREF(*p);
  389.             p++;
  390.         }
  391.     }
  392.     return (object *) np;
  393. }
  394.  
  395. static int
  396. list_ass_slice(a, ilow, ihigh, v)
  397.     listobject *a;
  398.     int ilow, ihigh;
  399.     object *v;
  400. {
  401.     /* Because [X]DECREF can recursively invoke list operations on
  402.        this list, we must postpone all [X]DECREF activity until
  403.        after the list is back in its canonical shape.  Therefore
  404.        we must allocate an additional array, 'recycle', into which
  405.        we temporarily copy the items that are deleted from the
  406.        list. :-( */
  407.     object **recycle, **p;
  408.     object **item;
  409.     int n; /* Size of replacement list */
  410.     int d; /* Change in size */
  411.     int k; /* Loop index */
  412. #define b ((listobject *)v)
  413.     if (v == NULL)
  414.         n = 0;
  415.     else if (is_listobject(v)) {
  416.         n = b->ob_size;
  417.         if (a == b) {
  418.             /* Special case "a[i:j] = a" -- copy b first */
  419.             int ret;
  420.             v = list_slice(b, 0, n);
  421.             ret = list_ass_slice(a, ilow, ihigh, v);
  422.             DECREF(v);
  423.             return ret;
  424.         }
  425.     }
  426.     else {
  427.         err_badarg();
  428.         return -1;
  429.     }
  430.     if (ilow < 0)
  431.         ilow = 0;
  432.     else if (ilow > a->ob_size)
  433.         ilow = a->ob_size;
  434.     if (ihigh < 0)
  435.         ihigh = 0;
  436.     if (ihigh < ilow)
  437.         ihigh = ilow;
  438.     else if (ihigh > a->ob_size)
  439.         ihigh = a->ob_size;
  440.     item = a->ob_item;
  441.     d = n - (ihigh-ilow);
  442.     if (ihigh > ilow)
  443.         p = recycle = NEW(object *, (ihigh-ilow));
  444.     else
  445.         p = recycle = NULL;
  446.     if (d <= 0) { /* Delete -d items; recycle ihigh-ilow items */
  447.         for (k = ilow; k < ihigh; k++)
  448.             *p++ = item[k];
  449.         if (d < 0) {
  450.             for (/*k = ihigh*/; k < a->ob_size; k++)
  451.                 item[k+d] = item[k];
  452.             a->ob_size += d;
  453.             NRESIZE(item, object *, a->ob_size); /* Can't fail */
  454.             a->ob_item = item;
  455.         }
  456.     }
  457.     else { /* Insert d items; recycle ihigh-ilow items */
  458.         NRESIZE(item, object *, a->ob_size + d);
  459.         if (item == NULL) {
  460.             XDEL(recycle);
  461.             err_nomem();
  462.             return -1;
  463.         }
  464.         for (k = a->ob_size; --k >= ihigh; )
  465.             item[k+d] = item[k];
  466.         for (/*k = ihigh-1*/; k >= ilow; --k)
  467.             *p++ = item[k];
  468.         a->ob_item = item;
  469.         a->ob_size += d;
  470.     }
  471.     for (k = 0; k < n; k++, ilow++) {
  472.         object *w = b->ob_item[k];
  473.         XINCREF(w);
  474.         item[ilow] = w;
  475.     }
  476.     if (recycle) {
  477.         while (--p >= recycle)
  478.             XDECREF(*p);
  479.         DEL(recycle);
  480.     }
  481.     return 0;
  482. #undef b
  483. }
  484.  
  485. int
  486. setlistslice(a, ilow, ihigh, v)
  487.     object *a;
  488.     int ilow, ihigh;
  489.     object *v;
  490. {
  491.     if (!is_listobject(a)) {
  492.         err_badcall();
  493.         return -1;
  494.     }
  495.     return list_ass_slice((listobject *)a, ilow, ihigh, v);
  496. }
  497.  
  498. static int
  499. list_ass_item(a, i, v)
  500.     listobject *a;
  501.     int i;
  502.     object *v;
  503. {
  504.     object *old_value;
  505.     if (i < 0 || i >= a->ob_size) {
  506.         err_setstr(IndexError, "list assignment index out of range");
  507.         return -1;
  508.     }
  509.     if (v == NULL)
  510.         return list_ass_slice(a, i, i+1, v);
  511.     INCREF(v);
  512.     old_value = a->ob_item[i];
  513.     a->ob_item[i] = v;
  514.     DECREF(old_value); 
  515.     return 0;
  516. }
  517.  
  518. static object *
  519. ins(self, where, v)
  520.     listobject *self;
  521.     int where;
  522.     object *v;
  523. {
  524.     if (ins1(self, where, v) != 0)
  525.         return NULL;
  526.     INCREF(None);
  527.     return None;
  528. }
  529.  
  530. static object *
  531. listinsert(self, args)
  532.     listobject *self;
  533.     object *args;
  534. {
  535.     int i;
  536.     object *v;
  537.     if (!getargs(args, "(iO)", &i, &v))
  538.         return NULL;
  539.     return ins(self, i, v);
  540. }
  541.  
  542. static object *
  543. listappend(self, args)
  544.     listobject *self;
  545.     object *args;
  546. {
  547.     object *v;
  548.     if (!getargs(args, "O", &v))
  549.         return NULL;
  550.     return ins(self, (int) self->ob_size, v);
  551. }
  552.  
  553. static object *comparefunc;
  554.  
  555. static int
  556. cmp(v, w)
  557.     const ANY *v, *w;
  558. {
  559.     object *t, *res;
  560.     long i;
  561.  
  562.     if (err_occurred())
  563.         return 0;
  564.  
  565.     if (comparefunc == NULL)
  566.         return cmpobject(* (object **) v, * (object **) w);
  567.  
  568.     /* Call the user-supplied comparison function */
  569.     t = mkvalue("(OO)", * (object **) v, * (object **) w);
  570.     if (t == NULL)
  571.         return 0;
  572.     res = call_object(comparefunc, t);
  573.     DECREF(t);
  574.     if (res == NULL)
  575.         return 0;
  576.     if (!is_intobject(res)) {
  577.         err_setstr(TypeError, "comparison function should return int");
  578.         i = 0;
  579.     }
  580.     else {
  581.         i = getintvalue(res);
  582.         if (i < 0)
  583.             i = -1;
  584.         else if (i > 0)
  585.             i = 1;
  586.     }
  587.     DECREF(res);
  588.     return (int) i;
  589. }
  590.  
  591. static object *
  592. listsort(self, args)
  593.     listobject *self;
  594.     object *args;
  595. {
  596.     object *save_comparefunc;
  597.     if (self->ob_size <= 1) {
  598.         INCREF(None);
  599.         return None;
  600.     }
  601.     save_comparefunc = comparefunc;
  602.     comparefunc = args;
  603.     if (comparefunc != NULL) {
  604.         /* Test the comparison function for obvious errors */
  605.         (void) cmp((ANY *)&self->ob_item[0], (ANY *)&self->ob_item[1]);
  606.         if (err_occurred()) {
  607.             comparefunc = save_comparefunc;
  608.             return NULL;
  609.         }
  610.     }
  611.     qsort((char *)self->ob_item,
  612.                 (int) self->ob_size, sizeof(object *), cmp);
  613.     comparefunc = save_comparefunc;
  614.     if (err_occurred())
  615.         return NULL;
  616.     INCREF(None);
  617.     return None;
  618. }
  619.  
  620. static object *
  621. listreverse(self, args)
  622.     listobject *self;
  623.     object *args;
  624. {
  625.     register object **p, **q;
  626.     register object *tmp;
  627.     
  628.     if (args != NULL) {
  629.         err_badarg();
  630.         return NULL;
  631.     }
  632.  
  633.     if (self->ob_size > 1) {
  634.         for (p = self->ob_item, q = self->ob_item + self->ob_size - 1;
  635.                         p < q; p++, q--) {
  636.             tmp = *p;
  637.             *p = *q;
  638.             *q = tmp;
  639.         }
  640.     }
  641.     
  642.     INCREF(None);
  643.     return None;
  644. }
  645.  
  646. int
  647. reverselist(v)
  648.     object *v;
  649. {
  650.     if (v == NULL || !is_listobject(v)) {
  651.         err_badcall();
  652.         return -1;
  653.     }
  654.     v = listreverse((listobject *)v, (object *)NULL);
  655.     if (v == NULL)
  656.         return -1;
  657.     DECREF(v);
  658.     return 0;
  659. }
  660.  
  661. int
  662. sortlist(v)
  663.     object *v;
  664. {
  665.     if (v == NULL || !is_listobject(v)) {
  666.         err_badcall();
  667.         return -1;
  668.     }
  669.     v = listsort((listobject *)v, (object *)NULL);
  670.     if (v == NULL)
  671.         return -1;
  672.     DECREF(v);
  673.     return 0;
  674. }
  675.  
  676. object *
  677. listtuple(v)
  678.     object *v;
  679. {
  680.     object *w;
  681.     object **p;
  682.     int n;
  683.     if (v == NULL || !is_listobject(v)) {
  684.         err_badcall();
  685.         return NULL;
  686.     }
  687.     n = ((listobject *)v)->ob_size;
  688.     w = newtupleobject(n);
  689.     if (w == NULL)
  690.         return NULL;
  691.     p = ((tupleobject *)w)->ob_item;
  692.     memcpy((ANY *)p,
  693.            (ANY *)((listobject *)v)->ob_item,
  694.            n*sizeof(object *));
  695.     while (--n >= 0) {
  696.         INCREF(*p);
  697.         p++;
  698.     }
  699.     return w;
  700. }
  701.  
  702. static object *
  703. listindex(self, args)
  704.     listobject *self;
  705.     object *args;
  706. {
  707.     int i;
  708.     
  709.     if (args == NULL) {
  710.         err_badarg();
  711.         return NULL;
  712.     }
  713.     for (i = 0; i < self->ob_size; i++) {
  714.         if (cmpobject(self->ob_item[i], args) == 0)
  715.             return newintobject((long)i);
  716.     }
  717.     err_setstr(ValueError, "list.index(x): x not in list");
  718.     return NULL;
  719. }
  720.  
  721. static object *
  722. listcount(self, args)
  723.     listobject *self;
  724.     object *args;
  725. {
  726.     int count = 0;
  727.     int i;
  728.     
  729.     if (args == NULL) {
  730.         err_badarg();
  731.         return NULL;
  732.     }
  733.     for (i = 0; i < self->ob_size; i++) {
  734.         if (cmpobject(self->ob_item[i], args) == 0)
  735.             count++;
  736.     }
  737.     return newintobject((long)count);
  738. }
  739.  
  740. static object *
  741. listremove(self, args)
  742.     listobject *self;
  743.     object *args;
  744. {
  745.     int i;
  746.     
  747.     if (args == NULL) {
  748.         err_badarg();
  749.         return NULL;
  750.     }
  751.     for (i = 0; i < self->ob_size; i++) {
  752.         if (cmpobject(self->ob_item[i], args) == 0) {
  753.             if (list_ass_slice(self, i, i+1, (object *)NULL) != 0)
  754.                 return NULL;
  755.             INCREF(None);
  756.             return None;
  757.         }
  758.             
  759.     }
  760.     err_setstr(ValueError, "list.remove(x): x not in list");
  761.     return NULL;
  762. }
  763.  
  764. static struct methodlist list_methods[] = {
  765.     {"append",    (method)listappend},
  766.     {"count",    (method)listcount},
  767.     {"index",    (method)listindex},
  768.     {"insert",    (method)listinsert},
  769.     {"sort",    (method)listsort, 0},
  770.     {"remove",    (method)listremove},
  771.     {"reverse",    (method)listreverse},
  772.     {NULL,        NULL}        /* sentinel */
  773. };
  774.  
  775. static object *
  776. list_getattr(f, name)
  777.     listobject *f;
  778.     char *name;
  779. {
  780.     return findmethod(list_methods, (object *)f, name);
  781. }
  782.  
  783. static sequence_methods list_as_sequence = {
  784.     (inquiry)list_length, /*sq_length*/
  785.     (binaryfunc)list_concat, /*sq_concat*/
  786.     (intargfunc)list_repeat, /*sq_repeat*/
  787.     (intargfunc)list_item, /*sq_item*/
  788.     (intintargfunc)list_slice, /*sq_slice*/
  789.     (intobjargproc)list_ass_item, /*sq_ass_item*/
  790.     (intintobjargproc)list_ass_slice, /*sq_ass_slice*/
  791. };
  792.  
  793. typeobject Listtype = {
  794.     OB_HEAD_INIT(&Typetype)
  795.     0,
  796.     "list",
  797.     sizeof(listobject),
  798.     0,
  799.     (destructor)list_dealloc, /*tp_dealloc*/
  800.     (printfunc)list_print, /*tp_print*/
  801.     (getattrfunc)list_getattr, /*tp_getattr*/
  802.     0,        /*tp_setattr*/
  803.     (cmpfunc)list_compare, /*tp_compare*/
  804.     (reprfunc)list_repr, /*tp_repr*/
  805.     0,        /*tp_as_number*/
  806.     &list_as_sequence,    /*tp_as_sequence*/
  807.     0,        /*tp_as_mapping*/
  808. };
  809.